package com.liuxl.wqdc.controller;

import com.liuxl.wqdc.DTO.ResponseDTO;
import com.liuxl.wqdc.service.ManagerService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin(origins = "*")
public class LoginController {
    @Autowired
    ManagerService managerService;

    @RequestMapping("/loginCheck")
    @ResponseBody
    public JSONObject checkLogin(@RequestParam String username, @RequestParam String password) {
        Integer result = managerService.checkLogin(username, password);
        if (result == 1) {
            return JSONObject.fromObject(new ResponseDTO(200, "success"));
        } else {
            return JSONObject.fromObject(new ResponseDTO(200, "用户名或密码不正确"));
        }
    }
}
